package Gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Gui {
	private JFrame frame;
	private JFrame configurationBoard;
	private Board quadro;
	private JLabel textSizeBoard = new JLabel("Tamanho do tabuleiro");
	private JLabel textNumSnake = new JLabel("Quantas cobras?");
	// {10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
	private Integer[] sizeBoard = { 30 };
	private Integer[] numSnake = { 2, 3, 4, 5 };
	private JComboBox<Integer> chooseSizeBoard = new JComboBox<Integer>(
			sizeBoard);
	private JComboBox<Integer> chooseNumSnake = new JComboBox<Integer>(numSnake);
	private JButton buttonOK;
	private JPanel panelSizeBoard = new JPanel();
	private JPanel panelnSnake = new JPanel();

	public Gui() {
		boardConfInit();

		buttonOK.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				boardSnakeInit();

				

				quadro.addMouseListener(new MouseListener() {

					@Override
					public void mouseReleased(MouseEvent e) {
						// quadro.setFin(e.getPoint());
					}

					@Override
					public void mousePressed(MouseEvent e) {
						// quadro.setInit(e.getPoint());

					}

					@Override
					public void mouseExited(MouseEvent arg0) {
						// TODO Auto-generated method stub

					}

					@Override
					public void mouseEntered(MouseEvent arg0) {
						// TODO Auto-generated method stub

					}

					@Override
					public void mouseClicked(MouseEvent e) {
						quadro.setSelected(e.getPoint());


					}
				}
				
						);

			}
		});

	}

	public void init() {
		configurationBoard.setVisible(true);
	}

	// Criar a board principal
	private void boardSnakeInit() {
		frame = new JFrame("The Game Snake");
		quadro = new Board(chooseSizeBoard.getItemAt(chooseSizeBoard
				.getSelectedIndex()));
		System.out
				.println("Dimensão "
						+ chooseSizeBoard.getItemAt(chooseSizeBoard
								.getSelectedIndex()));
		frame.getContentPane().add(quadro);
		frame.setResizable(false);
		frame.setSize(600, 622);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocation(300,0);
		configurationBoard.setVisible(true);
	}

	// criar uma janela de configurações para a board principal
	private void boardConfInit() {
		configurationBoard = new JFrame("Configuration Snake Game");
		configurationBoard.setLayout(new BorderLayout());
		configurationBoard.setSize(300, 130);
		configurationBoard.setLocation(800, 200);
		configurationBoard.setResizable(false);
		// Board
		panelSizeBoard.setLayout(new FlowLayout());
		panelSizeBoard.add(textSizeBoard);
		panelSizeBoard.add(chooseSizeBoard);
		configurationBoard.add(panelSizeBoard, BorderLayout.NORTH);
		// Snake
		panelnSnake.setLayout(new FlowLayout());
		panelnSnake.add(textNumSnake);
		panelnSnake.add(chooseNumSnake);
		configurationBoard.add(panelnSnake, BorderLayout.CENTER);
		// Botaçao de iniciar o jogo
		buttonOK = new JButton("Iniciar Jogo");
		configurationBoard.add(buttonOK, BorderLayout.SOUTH);
		// configurationBoard.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Colocar
		// no botão ao clicar OK

	}

	// public static void main(String[] args) {
	// new Gui().init();
	// }

}
